package app.netant.book.nt77;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Nt77Detail extends BaseDetail {

	public Nt77Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.77nt.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("body .main .info_top .xiaoshuo .info .title h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts2 = this.select("body .main .info_top .xiaoshuo .info .fullflag");
		if(parts2.size()>0){
			String state = parts2.get(0).text();
			int idx = state.indexOf("：");
			if(idx>0){
				state = state.substring(idx+1).trim();
			}
			System.out.println("【State】:"+state);
			this.entity.setNovelState(state);
		}
		
		Elements parts3 = this.select("body .main .info_top .xiaoshuo .info .title #author");
		if(parts3.size()>0){
			String writer = parts3.get(0).text();
			int idx = writer.indexOf("：");
			if(idx>0){
				writer = writer.substring(idx+1).trim();
			}
			System.out.println("【Writer】:"+writer);
			this.entity.setNovelWriter(writer);
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("body .main .info_top .xiaoshuo .info p");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTags(tags, true);
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("body .main .info_top .xiaoshuo .info-text");
		if(parts.size()>0){
			String memo = this.getString(parts.get(0).text());
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("body .main .info_top .xiaoshuo .read_link #txt_xiazai");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			Nt77Detail detail = new Nt77Detail(href);
			String url = detail.analyseStepHref();
			System.out.println("【Href】:"+url);
			this.entity.setDownPath(url);
		}
	}
	
	public String analyseStepHref(){
		
		Elements parts = this.select(".main #main #down_txt_url .txt_down a[rel='nofollow']");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			return href;
		}
		
		return null;
		
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("body .main .crumbs a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Nt77Detail detail = new Nt77Detail("https://www.77nt.com/book/105616.html");
		detail.test();
	}



}
